#include "aerial\IFCS.h"
#include "aerial\Weapon.h"

IFCS::IFCS(): count(0)
{
	head = new Weapon();
	tail = new Weapon();
	head->next = tail;
	tail->prev = head;
}

IFCS::~IFCS()
{
	Weapon *p = head, *q = p->next;
	for (; q; p = q, q = q->next) {
		delete p;
	}
	delete p;
}

void IFCS::addWeapon(Weapon* weap)
{
	weap->prev = tail->prev;
	weap->next = tail;
	tail->prev->next = weap;
	tail->prev = weap;
	weap->ifcs = this;
	++count;
}

Weapon* IFCS::removeWeapon(Weapon* weap)
{
	Weapon* t = weap->next;
	weap->prev->next = weap->next;
	weap->next->prev = weap->prev;
	delete weap;
	--count;
	return  t;
}

void IFCS::Update(float dt) {
	for (Weapon* p = head->next; p != tail; p = p->next)
		if (p->update(dt))
			p = removeWeapon(p)->prev;
}

void IFCS::Render()
{
	for (Weapon* p = head->next; p != tail; p = p->next) p->render();
}
